<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-yellow sidebar-mini">
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-editTask">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">修改任务状态</h4>
            </div>
            <div class="modal-body">
                <form id="editTaskForm" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label for="protNam" class="col-sm-2 control-label no-padding-right">任务名称</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="protNam" name="protNam" readonly="readonly">
                            <input type="hidden" style="display: none" id="protId" name="protId">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="protSta" class="col-sm-2 control-label no-padding-right">任务状态</label>
                        <div class="col-sm-10">
                            <select id="protSta" name="protSta" class="form-control">
                                <option value="1">未开始</option>
                                <option value="2">执行中</option>
                                <option value="3">已完成</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-saveTaskStatus">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-editReturn">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">修改反馈时间</h4>
            </div>
            <div class="modal-body">
                <form id="editReturnForm" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label for="prprNam" class="col-sm-2 control-label no-padding-right">反馈名称</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="prprNam" name="prprNam" readonly="readonly">
                            <input type="hidden" style="display: none" id="prprId" name="prprId">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="prprRetDat" class="col-sm-2 control-label no-padding-right">反馈时间</label>
                        <div class="col-sm-10">
                           <input name="prprRetDat" id="prprRetDat" class="form-control datepicker" readonly="readonly" />
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-saveReturn">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box" style="border: none;box-shadow: none">
                <div class="box-header">
                    <div class="row">
                        <h2>任务状态与反馈编辑</h2>
                    </div>
                    <div class="row">
                        <div class="form-inline">
                            <div class="form-group">
                                <label for="prodNo">生产令编号</label>
                                <label id="prodNo" th:text="${prodOrd.prodNo}"></label>
                            </div>
                            <div class="form-group">
                                <label for="proName">项目名称</label>
                                <label id="proName" th:text="${project.proName}"></label>
                            </div>
                        </div>
                    </div>
                    <form id="queryForm" style="display: none;">
                        <input name="protPropId" type="hidden" style="display: none" th:value="${prodPla.propId}" />
                        <input name="prprPropId" type="hidden" style="display: none" th:value="${prodPla.propId}" />
                    </form>
                </div>
                <div class="box-body">

                    <div class="col-md-6" style="border:1px #e9e9e9 solid">
                        <div class="row text-center">
                            <h4>任务</h4>
                        </div>
                        <div class="row">
                            <table id="bootstrap-table-task"></table>
                        </div>
                    </div>
                    <div class="col-md-6" style="border:1px #e9e9e9 solid;border-left: none">
                        <div class="row text-center">
                            <h4>反馈</h4>
                        </div>
                        <div class="row">
                            <table id="bootstrap-table-return"></table>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let taskTable,returnTable;
    /**
     * Jquery 就绪函数
     */
    $(function () {
        taskTable = js.table.init({
            url: ctx + "task/taskEditList",
            showColumns: false,
            showExport: false,
            id:'bootstrap-table-task',
            uniqueId: 'protId',
            columns: [
                {
                    title: '序号', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = taskTable.bootstrapTable('getOptions').pageSize;
                        var pageNumber = taskTable.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    title: '任务名称', field: 'protNam',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '状态', field: 'protSta',width: '75',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            if(value===1){
                                return '<label class="badge label-default">未开始</label>';
                            }else if(value===2){
                                return '<label class="badge label-warning">执行中</label>';
                            }else if(value===3){
                                return '<label class="badge label-success">已完成</label>';
                            }
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '操作',width: '60',
                    formatter: function (value, row, index) {
                        let actions = [];
                        if(row.protCod != 't27'){
                            actions.push('<button class="btn btn-warning btn-xs" type="button" onclick="editTask('+row.protId+')">编辑</button>');
                        }
                        return actions.join('');
                    }
                }
            ]
        });
        returnTable = js.table.init({
            url: ctx + "task/returnEditList",
            showColumns: false,
            showExport: false,
            id:'bootstrap-table-return',
            uniqueId: 'prprId',
            columns: [
                {
                    title: '序号', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = returnTable.bootstrapTable('getOptions').pageSize;
                        var pageNumber = returnTable.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    title: '反馈名称', field: 'prprNam',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '反馈时间', field: 'prprRetDat',width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                }
                ,
                {
                    title: '操作',width: '60',
                    formatter: function (value, row, index) {
                        let actions = [];
                        actions.push('<button class="btn btn-warning btn-xs" type="button" onclick="editReturn('+row.prprId+')">编辑</button>');
                        return actions.join('');
                    }
                }
            ]
        });
        /**
         * 保存任务状态
         */
        $("#btn-saveTaskStatus").on('click',function (){
            js.confirmPost({
                content: "尊敬的用户，您确认要保存此任务的状态码？",
                url: ctx + "task/saveTaskSta",
                data: $("#editTaskForm").serialize(),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.hide('modal-editTask');
                    js.table.refresh(taskTable);
                }
            });
        });

        /**
         * 验证
         */
        js.validate.init("editReturnForm", {
            fields: {
                prprRetDat: {validators: {notEmpty: {message: '尊敬的用户，请输入反馈时间！'}}}
            }
        });
        /**
         * 保存反馈时间
         */
        $("#btn-saveReturn").on('click',function (){
            js.validSubmit({
                formId: "editReturnForm",
                url: ctx + "task/saveReturn",
                data: new FormData($("#editReturnForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.modal.hide("modal-editReturn");
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.table.refresh(returnTable);
                }
            });
        });
        /**
         * 模态框隐藏事件， 重置表单，重置验证
         */
        js.modal.hideEvent("modal-editReturn", function () {
            js.validate.reset("editReturnForm");
            js.reset("editReturnForm");
        });
        /**
         * 模态框隐藏事件， 重置表单，重置验证
         */
        js.modal.hideEvent("modal-editTask", function () {
            js.reset("editTaskForm");
        });
    });

    /**
     * 编辑任务
     * @param protId
     */
    function editTask(protId){
        let row = $("#bootstrap-table-task").bootstrapTable('getRowByUniqueId', protId);
        $("#editTaskForm").fillData(row);
        js.modal.open('modal-editTask');
    }
    /**
     * 编辑任务
     * @param protId
     */
    function editReturn(prprId){
        let row = $("#bootstrap-table-return").bootstrapTable('getRowByUniqueId', prprId);
        $("#editReturnForm").fillData(row);
        js.modal.open('modal-editReturn');
    }

</script>
</body>
</html>